import {HTTP} from '@/utils/HTTP.js'
import {useState, useEffect} from "react";

const useAdminAllList = () => {
    const [adminList, setAdminList] = useState([])

    // console.log(res)
    useEffect(() => {

        async function getAdminList() {
            const adminRes = await HTTP({
                url: '/adminLogin/admin/alldata',
                method: 'GET'
            })
            const tableData = []
            for (let i = 0; i < adminRes.data.length; i++) {
                let update = new Date(adminRes.data[i].updatedAt)
                let created = new Date(adminRes.data[i].createdAt)
                const uptime = update.getFullYear() + "年" + (update.getMonth() + 1) + "月" + ("0" + update.getDate()).slice(-2) + "日" + " " + (update.getHours()) + "时" + (update.getMinutes()) + "分";

                const creative = created.getFullYear() + "年" + (created.getMonth() + 1) + "月" + ("0" + created.getDate()).slice(-2) + "日" + " " + (created.getHours()) + "时" + (created.getMinutes()) + "分";

                adminRes.data[i].updatedAt = uptime
                adminRes.data[i].createdAt = creative
                tableData.push(adminRes.data[i])
            }
            setAdminList(adminRes.data)
        }

        getAdminList()

    }, [])

    return {adminList}
}

export default useAdminAllList